home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / SOUND_KI / DATAFILE.C next >
Text File  |  1991-10-01  |  2KB  |  83 lines

  1. /*
  2. >>    Sound Kit
  3. >>
  4. >>    Copyright ⌐1991, Juri Munkki
  5. >>
  6. >>    This subroutines reads all data forks of a certain type from
  7. >>    the folder where it is run.
  8. >>
  9. >>    ReadDataFiles is only used by the compressing
  10. >>    part of the sound kit. You have to include this
  11. >>    file even if you are only decompressing the
  12. >>    sounds. Of course, the linker will remove this
  13. >>    routine when (and if) it notices that it's not used.
  14. */
  15.  
  16. #include "Shuddup.h"
  17.  
  18.  
  19. Handle    ReadDataFiles(ftype)
  20. long    ftype;
  21. {
  22.     register    Handle            fdata;
  23.     register    Handle            sinfo;
  24.     register    long            datasize;
  25.                 long            len;
  26.     register    int                numfiles,i,numread;
  27.                 int                ref;
  28.                 volumeParam        volupram;
  29.                 fileParam        filepram;
  30.                 char            fname[256];
  31.     
  32.     sinfo=GetResource(SKRESTYPE,SKSTABLE);
  33.     fdata=NewHandle(0);
  34.     datasize=0;
  35.  
  36.     volupram.ioCompletion=0;
  37.     volupram.ioNamePtr=0;
  38.     volupram.ioVRefNum=0;
  39.     volupram.ioVolIndex=0;
  40.     
  41.     PBGetVInfo(&volupram,0);
  42.  
  43.     numfiles=volupram.ioVNmFls;
  44.  
  45.     filepram.ioCompletion=0;
  46.     filepram.ioVRefNum=0;
  47.     filepram.ioFVersNum=0;
  48.     filepram.ioNamePtr=(void *)fname;
  49.     
  50.     numread=0;
  51.     for(i=1;i<=numfiles;i++)
  52.     {    filepram.ioFDirIndex=i;
  53.         if(PBGetFInfo(&filepram,0)==0)
  54.         {    if(filepram.ioFlFndrInfo.fdType==ftype)
  55.             {    if(FSOpen(fname,0,&ref)==0)
  56.                 {    if(GetEOF(ref,&len)==0)
  57.                     {    SetHandleSize(fdata,datasize+len);
  58.                         if(!MemErr)
  59.                         {    HLock(fdata);
  60.                             FSRead(ref,&len,datasize+*fdata);
  61.                             datasize+=len;
  62.                             HUnlock(fdata);
  63.                             
  64.                             numread++;
  65.                             SetHandleSize(sinfo,numread*sizeof(long));
  66.                             if(!MemErr)
  67.                             {    ((long *)(*sinfo))[numread-1]=len;
  68.                             }
  69.                         }
  70.                     }
  71.                     FSClose(ref);
  72.                 }
  73.             }
  74.         }
  75.     }
  76.     if(datasize==0)
  77.     {    datasize=10;
  78.     }
  79.     SetHandleSize(fdata,datasize);
  80.     ChangedResource(sinfo);
  81.     WriteResource(sinfo);
  82.     return fdata;
  83. }